using System;
using System.Collections.Generic;
using System.Linq;
namespace WebClient.Controllers
{
	#region using
	using System.Web.Mvc;
	using WebClient.Models.ViewModels;
	using WebClient.Models;
	using WebClient.Models.Repositories;
	using WebClient.Helpers;
	using System.Web.Security;
    using WebClient.CF_DAL_WS;
	#endregion
	public partial class AdminController: BaseController
	{
		public ActionResult SelectInformationWeb()
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_INFORMATIONWEB
			};
			return View(CreateViewModel(data));
		}



		public ActionResult DeleteInformationWeb(int id, int page = 1)
		{
			var result = _repInformationWeb.Delete(id);
			var data = new DataTransferViewModel
			{
				InfoText = result ? "Item has been deleted" : "Cannot delete item!",
				EnumViewModelType = EnumViewModel.ADMIN_INFORMATIONWEB,
				CurrentPage = page
			};
			return View("SelectInformationWeb", CreateViewModel(data));
		}

		public ActionResult EditInformationWeb(int page, int id)
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_INFORMATIONWEB,
				CurrentPage = page,
				IntID = id
			};
			return PartialView("Templates/TH_EditInformationWeb", CreateViewModel(data));
		}

		public ActionResult CancelEditingInformationWeb(int page)
		{
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_INFORMATIONWEB,
				CurrentPage = page
			};
			return PartialView("Templates/TH_ListInformationWeb", CreateViewModel(data));
		}

		[ValidateInput(false)]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult UpdateInformationWeb(FormCollection forms)
		{
			string id = forms.GetValues("InformationWeb_ID")[0];
			string email = forms.GetValues("InformationWeb_Email")[0];
			string passemail = forms.GetValues("InformationWeb_PassEmail")[0];
			string address = forms.GetValues("InformationWeb_Address")[0];
			var informationweb = _repInformationWeb.SelectByID(int.Parse(id));
			informationweb.Email = email;
			informationweb.PassEmail = passemail;
			informationweb.Address = address;
			var result = _repInformationWeb.Update(informationweb);
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_INFORMATIONWEB,
			};
			return View("SelectInformationWeb", CreateViewModel(data));
		}


		[ValidateInput(false)]
		[AcceptVerbs(HttpVerbs.Post)]
		public ActionResult InsertInformationWeb(FormCollection forms)
		{
			string email = forms.GetValues("InformationWeb_Email")[0];
			string passemail = forms.GetValues("InformationWeb_PassEmail")[0];
			string address = forms.GetValues("InformationWeb_Address")[0];
			var newItem = new InformationWebDTO
			{
				Email = email,
				PassEmail = passemail,
				Address = address
			};
			var result = _repInformationWeb.Insert(newItem);
			var data = new DataTransferViewModel
			{
				EnumViewModelType = EnumViewModel.ADMIN_INFORMATIONWEB,
				InfoText = result ? "New item has been added" : "Cannot insert new item"
			};
			return View("SelectInformationWeb", CreateViewModel(data));
		}


	}
}